package com.micro.train.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 火车餐实体类
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("火车餐")
public class TrainMeal {
    
    @TableId(value = "餐品ID", type = IdType.AUTO)
    private Long mealId;
    
    @TableField("列车ID")
    private Long trainId;
    
    @TableField("餐品名称")
    private String mealName;
    
    @TableField("餐品种类")
    private String mealType; // 盖饭、面食、饮品、零食等
    
    @TableField("价格")
    private BigDecimal price;
    
    @TableField("描述")
    private String description;
    
    @TableField("图片URL")
    private String imageUrl;
    
    @TableField("库存数量")
    private Integer stock;
    
    @TableField("状态")
    private Boolean available = true; // true-可订购, false-已售罄
    
    @TableField(value = "创建时间", fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    
    @TableField(value = "更新时间", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;
    
    @TableLogic
    @TableField("deleted")
    private Integer deleted;
    
    /**
     * 餐品种类枚举
     */
    public enum MealType {
        RICE("盖饭"),
        NOODLE("面食"),
        BEVERAGE("饮品"),
        SNACK("零食");
        
        private final String value;
        
        MealType(String value) {
            this.value = value;
        }
        
        public String getValue() {
            return value;
        }
    }
    
    /**
     * 更新库存方法
     */
    public boolean updateStock(int quantity) {
        if (quantity <= 0) {
            throw new IllegalArgumentException("数量必须大于0");
        }
        if (this.stock < quantity) {
            return false;
        }
        this.stock -= quantity;
        this.available = this.stock > 0;
        return true;
    }
}
